package person.crud.filter;

import java.sql.SQLException;
import java.util.ArrayList;
import person.model.Person;

//class do filter work
public class PersonCrud
{
    // clear from possible sql injects
    public static void clearString(String str)
    {
	ArrayList<String> ls = new ArrayList<String>();
	ls.add("/");
	ls.add("union");
	ls.add("select");
	ls.add("from");

	for (String s : ls)
	{
	    str.replaceAll(s, "");
	}

    }

    // just for usability
    public static void clear(Person p)
    {
	clearString(p.getfName());
	clearString(p.getSex());
	clearString(p.getlName());
	// ....
    }

    // filter person for some rules
    public static boolean filter(Person p) throws SQLException
    {
	boolean res = true;

	if (p.getfName().length() < 5 || p.getlName().length() < 5)
	    res = false;

	if (p.getSex().length() < 0 || p.getSex().length() > 1)
	    res = false;

	return res;
    }

}
